{extend name="adminblue/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
#productTbody td{padding:5px;font-size:12px;}
#productTbody td:first-child{border-left: 1px solid #E1E6F0;}
#productTbody td:last-child{border-right: 1px solid #E1E6F0;}
#productTbody tr:last-child td{border-bottom:1px solid #E1E6F0;}
.tr-title td{border-top: 1px solid #E1E6F0;}
.a-pro-view-img {float: left;}
.thumbnail-img {width: 60px;margin-right: 10px;height: 60px;}
.cell i {display: block;}
.remodal-bg.with-red-theme.remodal-is-opening,.remodal-bg.with-red-theme.remodal-is-opened {filter: none;}
.remodal-overlay.with-red-theme {background-color: #f44336;}
.remodal.with-red-theme {background: #fff;}
input[type="radio"], input[type="checkbox"] {margin: -1px 5px 0 0;}
.edit-group{border-bottom: 1px solid #ebebeb;margin-bottom:10px;}
.edit-group label{font-weight:normal;}
.edit-group-title{height:15px;line-height:15px;width:140px;margin-top:3px;margin-bottom:3px;color:#126AE4;}
.edit-group-button{border-color: #3283fa;border: 1px solid #bbb;height: 26px;line-height: 24px;padding: 0 5px;}
.group-button-bg{background: #3283fa;color: #fff;}
.div-pro-view-name {width: 100%;min-height: 60px;}
i.hot,i.recommend,i.new{font-size:12px;margin-right:5px;font-style:normal;color:#fff;background-color:#FF6600;border-radius:2px;padding:1px 4px;position: relative;top:-5px;}
.icon-qrcode:before {content: "\f029";}
[class^="icon-"]:before, [class*=" icon-"]:before {text-decoration: inherit;display: inline-block;speak: none;}
[class^="icon-"], [class*=" icon-"] {font-family: FontAwesome;font-weight: normal;font-style: normal;text-decoration: inherit;-webkit-font-smoothing: antialiased;}

input[type=number] {-moz-appearance:textfield;}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {-webkit-appearance: none;margin: 0;}
input, textarea, .uneditable-input {width: 147px;}
.table th, .table td {vertical-align: middle;}
.recommendBox{width: 360px;display: inline-block;float: right;}
.introduction_box{width: 360px;display: inline-block;float: right;}
.tab-content{overflow: visible;}
.editGoodsIntroduction{display: inline-block;border:1px dashed #fff;padding: 0;width: 350px;line-height: 25px;max-height: 60px;overflow: hidden;text-overflow: ellipsis;height: 25px;}
.editGoodsIntroduction:hover{border-color: #ddd;cursor: pointer;}
.editGoodsIntroduction + input{display: inline-block;padding: 0 5px;width: 350px!important;line-height: 27px;height: 27px!important;background: #EEF7FF;display: none;margin:0 0 5px !important;}
.editGoodsIntroduction>a{margin-left:0 !important;}
.goods-fields-sort{cursor:pointer;}
.goods-fields-sort span{background: url('ADMIN_IMG/goods_sort.png') no-repeat;width:20px;height:20px;display: inline-block;margin-left:5px;vertical-align: middle;position: absolute;}
.goods-fields-sort span.asc{background-position: 0 5px;}
.goods-fields-sort span.selected.asc{background-position: -30px 5px;}
.goods-fields-sort span.desc{background-position: 0 -24px;}
.goods-fields-sort span.selected.desc{background-position: -30px -24px;}
.more-search{line-height: 20px;background: #fff;outline: none}
.interval{width: 2px;display: inline-block;}
.ns-main{margin-top: 0;}
.btn-common-white,.btn-common{outline: none;line-height: 20px;display: inline-block;}
@media screen and (max-width:1260px) {
	a.btn-common{margin-bottom:5px !important;}
}
</style>
{/block}
{block name="main"}
<div class="js-mask-category" style="display:none;background: rgba(0,0,0,0);position:fixed;width:100%;height:100%;top:0;left:0;right:0;bottom:0;z-index:90;"></div>
<table class="mytable">
	<tr>
		<th align="left">
			<a class="btn-common" href="{:__URL('ADMIN_MAIN/goods/addgoods')}">发布商品</a>
			<!--<a class="btn-common-white" href="javascript:batchDelete()">批量删除</a>-->
			<!--<a class="btn-common-white upstore" href="javascript:goodsIdCount('online')">上架</a>-->
			<!--<a class="btn-common-white downstore" href="javascript:goodsIdCount('offline')">下架</a>-->
			<!--<a class="btn-common-white recommend" href="javascript:ShowRecommend()" data-html="true" id="setRecommend" title="推荐"-->
			<!--data-container="body" data-placement="bottom"  data-trigger="manual"-->
			<!--data-content="<div class='edit-group' id='recommendType'>-->
				<!--<label class='checkbox-inline'><i class='checkbox-common'><input type='checkbox' value='1' /></i> 热卖 </label>-->
				<!--<label class='checkbox-inline'><i class='checkbox-common'><input type='checkbox' value='2' /></i> 精品 </label>-->
				<!--<label class='checkbox-inline'><i class='checkbox-common'><input type='checkbox' value='3' /></i> 新品 </label>-->
				<!--</div>-->
				<!--<button class='btn-common btn-small' onclick='setRecommend();'>保存</button>-->
				<!--<button class='btn btn-small' onclick='hideSetRecommend()'>取消</button>-->
				<!--"-->
			<!--&gt;推荐</a>-->
			<!--<a data-html="true" class="btn-common-white fun-a category" href="javascript:goodsGroupIdCount();" id="editGroup" title="修改店内分类" data-container="body" data-placement="bottom"  data-trigger="manual"-->
				<!--data-content="<div class='edit-group' id='goodsChecked' style='max-width:auto;'>-->
					<!--{foreach $goods_group as $vo}-->
					<!--<label class='checkbox-inline'>-->
					<!--<i class='checkbox-common'><input type='checkbox' value='{$vo.group_id}'></i>-->
					<!--<span>{$vo.group_name}</span>&nbsp;&nbsp;&nbsp;-->
				<!--</label>-->
				<!--{foreach $vo['sub_list']['data'] as $vs}-->
				<!--<label style='display:inline-block;'>-->
					<!--<input type='checkbox' value='{$vs.group_id}'>{$vs.group_name}-->
					<!--</label>-->
					<!--{/foreach}-->
				<!--{/foreach}-->
				<!--</div>-->
				<!--<button class='btn-common btn-small' onclick='goodsGroupUpdate();'>保存</button>-->
				<!--<button class='btn btn-small' onclick='hideEditGroup()'>取消</button>-->
				<!--">-->
				<!--店内分类</a>-->
			<!--<a href="javascript:batchUpdateGoodsQrcode();;" class="btn-common-white fun-a category" title="更新二维码">更新二维码</a>-->
			<!--<a href="javascript:;" id="batchProcessing"  class="btn-common-white" title="批量处理">批量处理</a>-->
			<input type='hidden' id='goods_type_ids'/>
		</th>
		<th style="position: relative;">
			{include file='adminblue/Goods/goodsThreeCategory'/}
			<span class="interval"></span>
			<span>商品名称：</span>
			<input id="goods_name" class="input-medium input-common middle" type="text" value="{$search_info}" placeholder="要搜索的商品名称" >	
			<span class="interval"></span>
			<button class="btn-common-white more-search"><i class="fa fa-chevron-down"></i></button>
			<span class="interval"></span>
			<button onclick="searchData()" class="btn-common">搜索</button>
			
			<!-- 更多搜索 -->
			<div class="more-search-container">
				<dl>
					<dt>商品编码：</dt>
					<dd>
						<input id="goods_code" class="input-medium input-common middle" type="text" placeholder="要搜索的商品编码"/>
					</dd>
				</dl>
				<dl>
					<dt>供货商：</dt>
					<dd>
						<select id="supplier_id" class="select-common middle">
							<option value="">全部</option>
							{notempty name="$supplier_list"}
							{volist name="$supplier_list" id="vo"}
							<option value="{$vo.supplier_id}">{$vo.supplier_name}</option>
							{/volist}
							{/notempty}
						</select>
					</dd>
				</dl>
<!-- 				<dl> -->
<!-- 					<dt>上下架：</dt> -->
<!-- 					<dd> -->
<!-- 						<select id="state" class="select-common middle" > -->
<!-- 							<option value="" {if condition="$state neq ''"}selected{/if}>全部</option> -->
<!-- 							<option value="1" {if condition="$state == '1' "}selected{/if}>上架</option> -->
<!-- 							<option value="0" {if condition="$state eq '0' "}selected{/if}>下架</option> -->
<!-- 						</select> -->
<!-- 					</dd> -->
<!-- 				</dl> -->
				<dl>
					<dt>商品类型：</dt>
					<dd>
						<select id="goods_type" class="select-common middle" >
							<option value="all">全部</option>
							<option value="1">实物商品</option>
							<option value="0">虚拟商品</option>
						</select>
					</dd>
				</dl>
				<dl>
					<dt>店内分类：</dt>
					<dd>
						<input type="text" placeholder="请选择店内分类" id="selectGoodsLabel"  onfocus="selectGoodsLabel();" is_show="false" data-html="true" class="input-common middle" title="<h6 class='edit-group-title'>选择店内分类</h6>" data-container="body" data-placement="bottom"  data-trigger="manual" data-content="<div class='edit-group' style='max-width:auto;'>
							{foreach $goods_group as $vo}
							<p>
							<label class='checkbox-inline' style='display:inline-block;'>
							<input type='checkbox' value='{$vo.group_id}' onchange='clickGoodsLabel(this);'><span>{$vo.group_name}</span>&nbsp;&nbsp;&nbsp;
							</label>
						{/foreach}
						</div>
						<button class='btn-common btn-small' onclick='confirm();'>确认</button>
						<button class='btn btn-small' onclick='hideGroup()'>取消</button>
						">
					</dd>
				</dl>
				<dl>
					<dt></dt>
					<dd>
						<a href="javascript:;" onclick="searchData()" class="btn-common">完成</a>
					</dd>
				</dl>
			</div>
		</th>
	</tr>
</table>
<div id="myTabContent" class="tab-content">
	<div class="tab-pane active">
		<table class="table-class">
			<colgroup>
				<col style="width: 2%;">
				<col style="width: 25%;">
				<col style="width: 15%;">
				
				<col style="width: 15%;">
				<col style="width: 11%;">
				<col style="width: 11%;">
				<col style="width: 4%;">
				<col style="width: 15%;">
			</colgroup>
			<thead>
				<tr>
					<th>
						<i class="checkbox-common">
							<input onclick="CheckAll(this)" type="checkbox" id="chek_all">
						</i>
					</th>
					<th align="left">商品名称</th>
					<th class="goods-fields-sort" data-field="price" style="text-align: right;">价格(元)<span class="desc"></span></th>
					<th class="goods-fields-sort" data-field="stock" style="text-align: right;">总库存<span class="desc"></span></th>
					<th class="goods-fields-sort" data-field="sales" style="text-align: right;">销量<span class="desc"></span></th>
<!-- 					<th>上下架</th> -->
					<th>实物类型</th>
					<th class="goods-fields-sort" data-field="sort" style="text-align: center;">排序<span class="desc"></span></th>
					<th>操作</th>
				</tr>
				<!-- <tr>
					<td colspan="9" style="padding:10px 6px;border-left:1px solid #E1E6F0;border-right:1px solid #E1E6F0;">
						<a class="btn-common-child" href="{:__URL('ADMIN_MAIN/goods/addgoods')}">+发布商品</a>
						<a class="btn-common-child" href="javascript:batchDelete()">批量删除</a>
						<a class="btn-common-child upstore" href="javascript:goodsIdCount('online')">上架</a>
						<a class="btn-common-child downstore" href="javascript:goodsIdCount('offline')">下架</a>
						<a class="btn-common-child recommend" href="javascript:ShowRecommend()" data-html="true" id="setRecommend" title="推荐"
						data-container="body" data-placement="bottom"  data-trigger="manual"
						data-content="<div class='edit-group' id='recommendType'>
							<label class='checkbox-inline'><input type='checkbox' value='1'>热卖 </label>
							<label class='checkbox-inline'><input type='checkbox' value='2'>精品 </label>
							<label class='checkbox-inline'><input type='checkbox' value='3'>新品 </label>
							</div>
							<button class='btn-common btn-small' onclick='setRecommend();'>保存</button>
							<button class='btn btn-small' onclick='hideSetRecommend()'>取消</button>
							"
						>推荐</a>
						<a data-html="true" class="btn-common-child fun-a category" href="javascript:goodsGroupIdCount();" id="editGroup" title="修改店内分类" data-container="body" data-placement="bottom"  data-trigger="manual"
							data-content="<div class='edit-group' id='goodsChecked' style='max-width:auto;'>
 							{foreach $goods_group as $vo}
 							<p>
 							<label class='checkbox-inline' style='display:inline-block;' >
								<input type='checkbox' value='{$vo.group_id}'><span>{$vo.group_name}</span>&nbsp;&nbsp;&nbsp;
							</label>
							{foreach $vo['sub_list']['data'] as $vs}
							<label style='display:inline-block;'>
								<input type='checkbox' value='{$vs.group_id}'>{$vs.group_name}
								</label>
								{/foreach}
							</p>
							{/foreach}
							</div>
							<button class='btn-common btn-small' onclick='goodsGroupUpdate();'>保存</button>
							<button class='btn btn-small' onclick='hideEditGroup()'>取消</button>
							">
							店内分类</a>
						<a href="javascript:batchUpdateGoodsQrcode();;" class="btn-common-child fun-a category" title="更新二维码">更新二维码</a>
						<a href="javascript:;" id="batchProcessing"  class="btn-common-child" title="批量处理">批量处理</a>
						<input type='hidden' id='goods_type_ids'/>
					</td>
				</tr> -->
			</thead>
			<tbody id="productTbody" style="border: 0;"></tbody>
		</table>
	</div>
	<input type="hidden" id="state" value="{$state}"/>
	<input type="hidden" id="selectGoodsLabelId">
	<input type="hidden" id="stock_warning" value="{$stock_warning}">
</div>
<input type="hidden" id="hidden_sort_rule" />

<!-- 批量处理弹出框 -->
{include file="adminblue/Goods/batchProcessingModal" /}
{/block}
{block name="script"}
<script type="text/javascript">
$(function(){
	$(".js-update-goods-name,.js-update-introduction").live("blur",function(){
		var up_type = $(this).attr("data-up-type");
		var goods_id = $(this).attr("data-goods-id");
		var editContent = $(this).val();
		if(editContent == ""){
			if(up_type == "goods_name"){
				showTip("商品名不可为空","warning");
				$(this).focus();
				return false;
			}
		}
		var $self = $(this);
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/goods/ajaxEditGoodsNameOrIntroduction')}",
			data : {
				"goods_id" : goods_id,
				"up_type" : up_type,
				"up_content" : editContent
			},
			success : function(data){
				if(data['code'] > 0){
					if(up_type == "goods_name"){
						$self.prev(".editGoodsIntroduction").children("a").text(editContent);
					}else{
						$self.prev(".editGoodsIntroduction").children("span").text(editContent);
					}
				}
				$self.hide();
				$self.prev(".editGoodsIntroduction").show();
			}
		});
	}).live("keyup",function(event){
		if(event.keyCode == 13) $(this).blur();
	});
	
	//排序规则
	$(".goods-fields-sort").click(function(){
		
		var field = $(this).attr("data-field");
		var sort_rule = $(this).attr("data-field");
		$(this).siblings().css("color","#333333").find("span").removeClass("desc selected").addClass("desc");
		$(this).css("color","#126AE4");
		if($(this).find("span").hasClass("desc") && $(this).find("span").hasClass("selected")){
			$(this).find("span").removeClass("desc").addClass("selected asc");
			sort_rule += ",a";
		}else if(($(this).find("span").hasClass("asc") && $(this).find("span").hasClass("selected")) || $(this).find("span").hasClass("desc")){
			$(this).find("span").removeClass("asc").addClass("selected desc");
			sort_rule += ",d";
		}
		$("#hidden_sort_rule").val(sort_rule);
		LoadingInfo(1);
	});

});

function searchData(){
	$(".more-search-container").slideUp();
	LoadingInfo(1);
}

//隐藏商品分组
function hideEditGroup(){
	$("#editGroup").popover("hide");
}

function hideSetRecommend(){
	$("#setRecommend").popover("hide");
}

function LoadingInfo(page_index) {
	
	var start_date = $("#startDate").val();
	var end_date = $("#endDate").val();
	var state = $("#state").val();
	var goods_name =$("#goods_name").val();
	var goods_code = $("#goods_code").val();
	var category_id_1 = $("#category_id_1").val();
	var category_id_2 = $("#category_id_2").val();
	var category_id_3 = $("#category_id_3").val();
	var selectGoodsLabelId = $("#selectGoodsLabelId").val();
	var supplier_id = $("#supplier_id").val();
	var stock_warning = $("#stock_warning").val();
	var goods_type = $("#goods_type").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/goods/goodslist')}",
		data : {
			"page_index" : page_index,
			"page_size" : $("#showNumber").val(),
			"start_date":start_date,
			"end_date":end_date,
			"state":state,
			"goods_name":goods_name,
			"code":goods_code,
			"category_id_1" : category_id_1,
			"category_id_2" : category_id_2,
			"category_id_3" : category_id_3,
			"selectGoodsLabelId" : selectGoodsLabelId,
			"supplier_id" : supplier_id,
			"stock_warning" : stock_warning,
			'sort_rule' : $("#hidden_sort_rule").val(),
			'goods_type' : goods_type
		},
		success : function(data) {

			if (data["data"].length > 0) {
				$("#productTbody").empty();
				for (var i = 0; i < data["data"].length; i++) {

					var html = '';
					html += '<tr class="tr-title">';
						html += '<td class="td-'+ data["data"][i]["goods_id"]+'" style="border-bottom:0;">';
// 							html += '<label style="text-align: center;vertical-align: middle;margin: 0 0 0 -1px;">';
// 								html += '<i class="checkbox-common"><input value="' + data["data"][i]["goods_id"] + '" name="sub" data-state="'+data["data"][i]["state"]+'" type="checkbox"></i>';
// 							html += '</label>';
						html += '</td>';

						html += '<td colspan="9" style="border-bottom:0;">';
							html += '<div style="display: inline-block; width: 100%;font-size:12px;color:#666;" class="pro-code">';
								html += '<span>商家编码'+'：' + data["data"][i]["code"] + '</span>';
								html += '<span class="pro-code" style="margin-left:10px;">创建时间：'+timeStampTurnTime(data["data"][i]["create_time"]);
									html += '<span class="div-flag-style" style="display: inline-block;margin:0 20px;position:relative">';
										// html += '<i class="icon-qrcode"style="background: none; color: #555; font-size: 20px; margin-right: 0;"></i>';
										// html += '<div class="QRcode" style="display: none; position: absolute;width:110px;top:28px;left:0;z-index:10;"id="qrcode">';
										// 	html += '<p><img src="'+ __IMG(data["data"][i]["QRcode"])+'" style="width:110px;"></p>';
										// html += '</div>';
									html += '</span>';
								html += '</span>';
							html += '</div>';
						html += '</td>';
					html += '</tr>';

					html += '<tr>';
						html += '<td align="center">';
							html += '<i class="checkbox-common"><input value="' + data["data"][i]["goods_id"] + '" name="sub" data-state="'+data["data"][i]["state"]+'" type="checkbox"></i>';
						html += '</td>';
						html += '<td colspan="1">';
							html += '<div style="width:450px;">';
								html += '<a class="a-pro-view-img" href="'+__URL('SHOP_MAIN/goods/goodsinfo?goodsid='+data["data"][i]["goods_id"])+'" target="_blank" style="height:70px;line-height:70px;text-align:center;">';
									html += '<img class="thumbnail-img" src="'+__IMG(data["data"][i]["pic_cover_micro"])+'">';
								html += '</a>';
								html += '<div class="div-pro-view-name">';
// 									html += '<span class="thumbnail-name" title='+ data["data"][i]["goods_name"]+'">';
										html += '<div class="editGoodsIntroduction" ondblclick="editGoodsInfo(this)">';
											html += '<a  style="word-break:break-all;" href="javascript:;">' + data["data"][i]["goods_name"] + '</a>';
										html += '</div>';
										html += '<input class="js-update-goods-name input-common" data-goods-id ="' + data['data'][i]['goods_id'] + '" data-up-type="goods_name" type="text" value="'+data["data"][i]['goods_name']+'"/>';
// 									html += '</span>';
									html += '<br/>';

									if(data["data"][i]['introduction'] != '' && data["data"][i]['introduction'] != undefined){

									html += '<div class="editGoodsIntroduction" ondblclick="editGoodsInfo(this)">';
										html += '<span style="color:#999;font-size:12px;display:block;height:25px;overflow:hidden;text-decoration: none;">'+data["data"][i]['introduction']+'</span>';
									html += '</div>';
									html += '<input data-goods-id ="' + data['data'][i]['goods_id'] + '" data-up-type="introduction" class="js-update-introduction input-common" type="text" maxlength="60" value="'+data["data"][i]['introduction']+'" />';

									}
									html += '<div style="position: relative;margin-left: 75px;">';
										html += data["data"][i]["is_hot"] == 1 ? '<i class="hot">热</i>' : '';
										html += data["data"][i]["is_recommend"] == 1 ? '<i class="recommend">精</i>' : '';
										html += data["data"][i]["is_new"] == 1 ? '<i class="new">新</i>' : '';
										if(data["data"][i]['goods_group_name'] != '' && data["data"][i]['goods_group_name'] != undefined){
											var tmp_array = data["data"][i]['goods_group_name'].split(",");
											$.each(tmp_array,function(k,v){	
												if(v != ""){
													html += '<i style="color:#999;font-size:12px;margin-top:5px;padding:1px 4px;border-radius:3px;display:inline-block;color:#FFF;background-color:#FF6600;text-decoration: none;height:16px;line-height: 16px;overflow:hidden;margin-right:5px;text-align:center;font-style:normal;">'+v+'</i>';
												}
											});
										}
									html += '</div>';
								html += '</div>';
							html += '</div>';
						html += '</td>';

						html += '<td style="text-align: right;">';
							// if(data["data"][i]["price"] != data["data"][i]["promotion_price"]){
								html += '<div class="priceaddactive">';
									html += '<span class="price-lable">原&nbsp;&nbsp;&nbsp;价：</span>';
									html += '<span class="price-numble" style="color: #666;"id="moreChangePrice'+ data["data"][i]["goods_id"]+'">' + data["data"][i]["price"] + '</span>';
								html += '</div>';
							// }
							// if(data["data"][i]["promotion_price"]){
                                html += '<div>';
                                html += '<span class="price-lable">促销&nbsp;价：</span>';

                                html += '<span class="price-numble"id="moreChangePrice'+ data["data"][i]["goods_id"]+'" style="color:#FF6600;">' + data["data"][i]["promotion_price"] + '</span>';
                                html += '</div>';
							// }
						html += '</td>';

						html += '<td style="text-align: right;">';
							html += '<div class="cell">';
								html += '<span class="pro-stock" style="color: #666;" id="moreChangeStock'+ data["data"][i]["goods_id"] + '">' + data["data"][i]["stock"] + '</span>';
							html += '</div>';
						html += '</td>';

						html += '<td style="text-align: right;">';
							html += '<div class="cell">';
								html += '<span class="pro-stock" style="color: #666;" id="moreChangeStock'+ data["data"][i]["goods_id"]+'">' + data["data"][i]["real_sales"] + '</span>';
							html += '</div>';
						html += '</td>';
						
						html += '<td style="text-align: center;">';
						if(data['data'][i]['goods_type'] == 1){
							html += '<span>实物类</span>';
						}else{
							html += '<span>虚拟类</span>';
						}
						html += '</td>';

						html += '<td style="text-align: center;">';
							html += '<div class="cell">';
								html += '<input class="input-common input-common-sort" goods_id="' + data["data"][i]["goods_id"] + '"  value="' + data["data"][i]["sort"] + '" onchange="changeSort(this)"' + 'type="number" title="排序号数值越大，商城商品列表显示越靠前">';
							html += '</div>';
						html += '</td>';

						html += '<td>';
							html += '<div class="bs-docs-example tooltip-demo"style="text-align: center;">';
                    html += '<a href="' + __URL("ADMIN_MAIN/goods/addgoods?step=2&goodsId=" + data["data"][i]["goods_id"]) + '" title="编辑商品" >编辑</a>';

                    if(data["data"][i]["state"] != 3) {
                                    html += '<a href="javascript:deleteGoods(' + data["data"][i]["goods_id"] + ')" title="删除商品">删除</a>';
                  				}
								// html += '<a href="javascript:copyGoodsDetail(' + data["data"][i]["goods_id"] + ');" title="复制商品" >复制</a>';

								if(data["data"][i]["state"] == 1){
									html += '<br/><a href="javascript:modifyGoodsOnline('+data["data"][i]["goods_id"]+',\'offline\')">下架</a>';
								}else if(data["data"][i]["state"] == 3){
									html += '<br/><a href="javascript:;">审核中</a>';
								}else{
									html += '<br/><a href="javascript:modifyGoodsOnline('+data["data"][i]["goods_id"]+',\'online\')" style="color:#999;">上架</a>';
								}
								// if(data['data'][i]['goods_type'] == 0){
								// 	html += '<br/><a href="' + __URL("ADMIN_MAIN/goods/virtualGoodsList?goods_id="+ data["data"][i]["goods_id"]) + '" title="虚拟商品管理" target="_blank" >虚拟商品管理</a>';
								// }
							html += '</div>';
						html += '</td>';
					html += '</tr>';
					$("#productTbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9" style="text-align: center;font-weight: normal;color: #999;">暂无符合条件的数据记录</td></tr>';
				$("#productTbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
			code();
		}
	});
}

//二维码
function code(){
	$(".div-flag-style").mouseover(function(){
		$(this).children('.QRcode').show();
	});
	$(".div-flag-style").mouseout(function(){
		$(this).children('.QRcode').hide();
	});
} 

//把值传过去即可
function updateGoodsDetail(goods_id) {
	window.location = __URL("ADMIN_MAIN/goods/addgoods?step=2&goodsId="+ goods_id);
}

//全选
function CheckAll(event){
	var checked = event.checked;
	$("#productTbody input[type = 'checkbox']").prop("checked",checked);
	if(checked) $(".table-class tbody input[type = 'checkbox']").parent().addClass("selected");
	else $(".table-class tbody input[type = 'checkbox']").parent().removeClass("selected");
}

//商品上架id合计
function goodsIdCount(line){
	var goods_ids= "";
	$("#productTbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			var state = $(this).data("state");
//			if(line == "online"){
//				if(state == 1){
//					$( "#dialog" ).dialog({
//						buttons: {
//							"确定": function() {
//								$(this).dialog('close');
//							}
//						},
//						contentText:"记录中包含已上架记录",
//						title:"消息提醒",
//					});
//					return false;
//				}
//			}else{
//				if(state == 0){
//					$( "#dialog" ).dialog({
//						buttons: {
//							"确定": function() {
//								$(this).dialog('close');
//							}
//						},
//						contentText:"记录中包含已下架记录",
//						title:"消息提醒",
//					});
//				return false;
//				}
//			}
			goods_ids = $(this).val() + "," + goods_ids;
		}
	});
	goods_ids = goods_ids.substring(0, goods_ids.length - 1);
	if(goods_ids == ""){
		showTip("请选择需要操作的记录","warning");
		return false;
	}
	modifyGoodsOnline(goods_ids,line);
}

//商品上下架
function modifyGoodsOnline(goods_ids,line){
	if(line == "online"){
		var url = "{:__URL('ADMIN_MAIN/Goods/modifygoodsonline')}";
		var lingStr = "上架";
	}else{
		var url = "{:__URL('ADMIN_MAIN/Goods/modifygoodsoffline')}";
		var lingStr = "下架";
	}
	$.ajax({
		type : "post",
		url : url,
		data : { "goods_ids" : goods_ids },
		success : function(data) {
			if(data["code"] > 0 ){
				LoadingInfo(getCurrentIndex(goods_ids,'#productTbody','tr[class="tr-title"]'));
				showTip("商品"+lingStr+"成功","success");
			}
		}
	})
}

function batchDelete() {
	var goods_ids= new Array();
	$("#productTbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			goods_ids.push($(this).val());
		}
	});
	if(goods_ids.length ==0){
		showTip("请选择需要操作的记录","warning");
		return false;
	}
	deleteGoods(goods_ids);
}

function deleteGoods(goods_ids){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$.ajax({
					type : "post",
					url : "{:__URL('ADMIN_MAIN/goods/deletegoods')}",
					data : { "goods_ids" : goods_ids.toString() },
					dataType : "json",
					success : function(data) {
						if(data["code"] > 0 ){
							LoadingInfo(getCurrentIndex(goods_ids,'#productTbody','tr[class="tr-title"]'));
							showTip(data['message'],"success");
							$("#chek_all").prop("checked", false);
						}
					}
				});
				$(this).dialog('close');
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			},
		},
		contentText:"确定要删除吗？",
	});
}

//商品修改分组id合计
function goodsGroupIdCount(){
	var goods_ids= "";
	$("#productTbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			goods_ids = $(this).val() + "," + goods_ids;
		}
	});
	goods_ids = goods_ids.substring(0, goods_ids.length - 1);
	if(goods_ids == ""){
		showTip("请选择需要操作的记录","warning");
		return false;
	}
	$("#goods_type_ids").val(goods_ids);
	$("#editGroup").popover("show");
	$(".popover").css("max-width",'1000px');
}

//商品修改分组
function goodsGroupUpdate(){
	var goods_type = "";
	var goods_ids = $("#goods_type_ids").val();
	$("#goodsChecked input[type='checkbox']:checked").each(function(){
		if (!isNaN($(this).val())) {
			goods_type = $(this).val() + "," + goods_type;
		}
	})
	// if(goods_type == ""){
	//	showTip("请选择需要操作的记录","warning");
	// 	$( "#dialog" ).dialog({
	// 		buttons: {
	// 			"确定": function() {
	// 				$(this).dialog('close');
	// 			}
	// 		},
	// 		contentText:"请选择需要操作的记录",
	// 		title:"消息提醒",
	// 	});
	// 	return false;
	// }
	goods_type = goods_type.substring(0, goods_type.length - 1);
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/goods/modifygoodsgroup')}",
		data : { "goods_id" : goods_ids, "goods_type" : goods_type },
		success : function(data) {
			if(data["code"] > 0 ){
				$("#editGroup").popover("hide");
				LoadingInfo(getCurrentIndex(goods_ids,'#productTbody','tr[class="tr-title"]'));
				showTip(data['message'],"success");
			}
		}
	})
}

//显示 推荐选项
function ShowRecommend(){
	var goods_ids= "";
	$("#productTbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			goods_ids = $(this).val() + "," + goods_ids;
		}
	});
	goods_ids = goods_ids.substring(0, goods_ids.length - 1);
	if(goods_ids == ""){
		showTip("请选择需要操作的记录","warning");
		return false;
	}
	$("#goods_type_ids").val(goods_ids);
	$("#setRecommend").popover("show");
}

$("#recommendType label,#recommendType label input").live("click",function(){
// 	if($(this).children("input").is(":checked")){
// 		$(this).children("input").prop("checked",false);
// 	}else{
// 		$("#recommendType label input").prop("checked",false);
// 		$(this).children("input").prop("checked",true);
// 	}
})

//修改为  推荐 商品
function setRecommend(){
	var recommend_type = '';
	var goods_ids = $("#goods_type_ids").val();
	$("#recommendType input[type='checkbox']").each(function(){
		if ($(this).attr("checked") == 'checked') {
			var recommend_type_new = 1;
		}else{
			var recommend_type_new = 0;
		}
		recommend_type = recommend_type_new + "," + recommend_type;
	})
	if(recommend_type == ""){
		showTip("请选择需要操作的记录","warning");
		return false;
	}
	recommend_type = recommend_type.substring(0, recommend_type.length - 1);
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/goods/modifygoodsrecommend')}",
		data : {
			"goods_id" : goods_ids,
			"recommend_type" : recommend_type
		},
		success : function(data) {
			if(data["code"] > 0 ){
				$("#setRecommend").popover("hide");
				LoadingInfo(getCurrentIndex(goods_ids,'#productTbody','tr[class="tr-title"]'));
				showTip(data['message'],"success");
			} 
		}
	})
}

function copyGoodsDetail(goods_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$.ajax({
					type : "post",
					url : "{:__URL('ADMIN_MAIN/goods/copygoods')}",
					data : {"goods_id":goods_id},
					dataType : "json",
					success : function(data) {
						if(data["code"] > 0 ){
							LoadingInfo(getCurrentIndex(goods_id,'#productTbody','tr[class="tr-title"]'));
							showTip(data["message"],"success");
							$("#chek_all").prop("checked", false);
						}else{
							showTip(data["message"],"error");
						}
					}
				});
				$(this).dialog('close');
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			},
		},
		contentText:"确定要复制一条新的商品信息吗？",
	});
}

function changeSort(event){
	var sort = parseInt($(event).val());
	$(event).val(sort);
	var goods_id = $(event).attr("goods_id");
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/goods/updateGoodsSortAjax')}",
		data : { "sort" : sort, "goods_id" : goods_id },
		success : function(data){
			if(data.code>0){
				LoadingInfo(getCurrentIndex(goods_id,'#productTbody','tr[class="tr-title"]'));
				showTip(data.message,"success");
			}else{
				showTip(data.message,"error");
			}
		}
	})
}

//更新二维码
function batchUpdateGoodsQrcode(){
	var goods_ids= new Array();
	$("#productTbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			goods_ids.push($(this).val());
		}
	});
	if(goods_ids.length == 0){
		showTip("请至少选择一件商品","warning");
		return false;
	}
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/goods/updateGoodsQrcode')}",
		data : { "goods_id" : goods_ids.toString() },
		success : function(data){
			if (data["code"] > 0) {
				LoadingInfo(getCurrentIndex(goods_ids,'#productTbody','tr[class="tr-title"]'));
				showTip('二维码更新成功',"success");
			}else{
				showTip(data['message'],"error");
			}
		}
	})
}

function selectGoodsLabel(){
	$("#selectGoodsLabel").popover("show");
	$("#selectGoodsLabelId").val('');
	$("#selectGoodsLabel").val('');
}

function hideGroup(){
	$("#selectGoodsLabel").popover("hide");
	$("#selectGoodsLabel").val('');
}

function clickGoodsLabel(event){
	var goods_label_id = $(event).val();
	var goods_label_name = $(event).next("span").text();
	var selectGoodsLabelVal = $("#selectGoodsLabel").val();
	var selectGoodsLabelId = $("#selectGoodsLabelId").val();
	if($(event).is(":checked")){
		$("#selectGoodsLabelId").val(selectGoodsLabelId+goods_label_id+',');
		$("#selectGoodsLabel").val(selectGoodsLabelVal+goods_label_name+';');
	}else{
		selectGoodsLabelVal = selectGoodsLabelVal.replace(goods_label_name+';','');
		selectGoodsLabelId = selectGoodsLabelId.replace(goods_label_id+',','');
		$("#selectGoodsLabelId").val(selectGoodsLabelId);
		$("#selectGoodsLabel").val(selectGoodsLabelVal);
	}
}

function confirm(){
	$("#selectGoodsLabel").popover("hide");
}

function editGoodsInfo(event){
	$(event).hide();
	$(event).next("input").show().focus();
}
// 点击显示更多搜索
$(".more-search").click(function(){
	$(".more-search-container").slideToggle();
})

// 批量处理弹出框
$("#batchProcessing").click(function(){
	var goods_ids= new Array();
	$("#productTbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			goods_ids.push($(this).val());
		}
	});
	if(goods_ids.length == 0){
		showTip("请至少选择一件商品","warning");
		return false;
	}
	$("#batch_processing").modal("show");
})
</script>
{/block}